"""
@-*- coding: utf-8 -*-
@ python: 3.12.3
@ 创建者: JacksonCode
@ 创建时间: 2025-11-23
"""
import oracledb
import os

username = os.getenv("DB_USER")
password = os.getenv("DB_PWD")
host = os.getenv("DB_HOST")
port = int(os.getenv("DB_PORT",1521))
service_name = os.getenv("DB_SERVICE_NAME","ORCL")

# 构建 DSN（Data Source Name）
dsn = f"{host}:{port}/{service_name}"

# 连接数据库（Thin 模式默认启用）
connection = oracledb.connect(user=username, password=password, dsn=dsn)

print("成功连接到 Oracle 数据库！")

# 创建游标
cursor = connection.cursor()

# 执行查询
cursor.execute("SELECT * FROM WATER_PMETER ")
rows = cursor.fetchall()
for row in rows:
    print(row)

# 关闭资源
cursor.close()
connection.close()